package com.jbm.core.common;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.keepalive.KeepAliveMessageFactory;

/**
 * Created by root on 16-1-19.
 */
enum HBType
{
    SERVER,CLIENT;
}

public class JBMKeepAliveMessageFactory implements KeepAliveMessageFactory {
    public JBMKeepAliveMessageFactory ( HBType hbtype )
    {
        this.hbtype = hbtype;
    }

    public HBType hbtype;

    @Override
    public boolean isRequest ( IoSession session, Object message )
    {
        if ( hbtype == HBType.SERVER )
            return message.equals("request");
        else
            return false;
    }

    @Override
    public boolean isResponse ( IoSession session, Object message )
    {
        if ( hbtype == HBType.CLIENT )
            return message.equals("response");
        else
            return false;
    }

    @Override
    public Object getRequest ( IoSession session )
    {
        if ( hbtype == HBType.CLIENT )
            return "request";
        else
            return null;
    }

    @Override
    public Object getResponse ( IoSession session, Object request )
    {
        if ( hbtype == HBType.SERVER )
            return "response";
        else
            return null;
    }
}
